home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tex / inputs / vdm-doc.tex < prev    next >
Encoding:
Text File  |  1991-05-21  |  44.8 KB  |  1,404 lines

  1. \documentstyle[vdm]{article}
  2.  
  3. \title{Typesetting VDM with \LaTeX}
  4. \author{Mario Wolczko\\
  5. Dept. of Computer Science\\
  6. The University\\
  7. Manchester M13 9PL\\
  8. U.K.\\
  9. \verb;mario@uk.ac.man.cs.r5;, {\tt ...!mcvax!ukc!man.cs.r5!mario}}
  10. \date{March 1988}
  11.  
  12. \newcommand{\Vdm}{{\tt vdm\/}}
  13.  
  14. \newenvironment{dangerous}{\endgraf\vspace{5pt}\bgroup\small}%
  15.               {\endgraf\egroup\vspace{5pt}}
  16.  
  17. \newlength{\righthalf} \setlength{\righthalf}{0.5\textwidth}
  18. \newlength{\lefthalf}  \setlength{\lefthalf}{0.4\textwidth}
  19. \newenvironment{leftside}{\noindent\hspace{0.1\textwidth}%
  20.               \parbox[t]{\lefthalf}\bgroup\vspace{10pt}%
  21.               \noindent\begin{vdm}\leftskip=0pt\VDMindent=0pt}%
  22.              {\end{vdm}\egroup}
  23. \newenvironment{rightside}{\parbox[t]{\righthalf}\bgroup\begin{verbatim}}%
  24.               {\egroup}
  25.  
  26. \renewcommand{\^}[1]{$\langle${\rm #1\/}$\rangle$}
  27.  
  28. \newcommand{\mmexp}{\^{math-mode-expression}}
  29. \newcommand{\cs}[1]{{\tt \string#1}}
  30.  
  31. \setlength{\VDMindent}{3\parindent}
  32.  
  33. \setlength{\preOperationSkip}{0pt}
  34. \setlength{\preFunctionSkip}{0pt}
  35. \setlength{\preTypeSkip}{0pt}
  36. \setlength{\preCompositeSkip}{0pt}
  37. \setlength{\preRecordSkip}{0pt}
  38. \setlength{\preFormulaSkip}{0pt}
  39.  
  40. \begin{document}
  41. \maketitle
  42.  
  43. \tableofcontents
  44.  
  45. This document describes a new style option, \Vdm, for use with
  46. \LaTeX.  The purpose of \Vdm\ is to make the typesetting of VDM
  47. specifications easy.  Other goals are:
  48. \begin{itemize}
  49. \item    To enable users of \Vdm\ to communicate their specifications
  50.     to others, possibly in a variety of concrete syntaxes, without
  51.     having to change their source files
  52. \item    To help the VDM community standardise on a particular form of VDM.
  53.     This, of course, is in direct contradiction to the first
  54.     aim
  55. \item    To enable a user of \Vdm\ to concentrate on his%
  56.     \footnote{Read `his/her' for every occurence of `his'.}
  57.     specifications, and ignore the detailed layout as much as
  58.     possible.  A side effect of this is that the effort required
  59.     to improve layout is concentrated in one place, within the
  60.     \Vdm\ macros.
  61. \end{itemize}
  62.  
  63. But enough evangelising.  Let's get to the the real meat.  This
  64. document is broken up into the following sections:
  65. \begin{itemize}
  66. \item    General points about using \Vdm
  67. \item    Typesetting formulas
  68. \item    How to typeset data types
  69. \item    How to typeset functions
  70. \item    How to typeset operations
  71. \item    How to typeset proofs
  72. \item    How to tailor/extend the system for your own
  73.     application.
  74. \end{itemize}
  75. You should definitely read the first two sections---then you'll know
  76. roughly what you're in for, and whether you want to continue.  The
  77. remaining sections can be read as and when you need them.
  78.  
  79. \begin{dangerous}
  80. In keeping with the best traditions of \TeX\ documentation, paragraphs
  81. that contain material that is not essential for novices, but vital if
  82. you want to parameterise or extend the system, are in smaller type,
  83. like this one.
  84. \end{dangerous}
  85.  
  86. Just to give a preliminary example, here is some output from \Vdm, and
  87. the corresponding input:
  88.  
  89. \begin{vdm}
  90. \begin{fn}{dec}{ptrs,om} \\
  91. \signature{
  92.      \setof{Oop} \x \mapof{Oop}{Object} \to \mapof{Oop}{Object} 
  93. }
  94. \If ptrs = \emptyset
  95. \Then om
  96. \Else     \Let gone = \set{p \in ptrs | RC(om(p)) = 1} \In
  97.     \Let om' = gone \dsub om \In
  98.     \Let om'' = om' \owr
  99.         \map{p \mapsto \chg{om'(p)}{RC}{RC\minus 1}\T3
  100.             | p \in ptrs \diff gone} \In
  101.     dec(\Union\set{\elems{BODY(om(p))} | p \in gone}, om'')
  102. \Fi
  103. \end{fn}
  104.  
  105. \begin{op}[DESTROYPTR]\label{op-ex}
  106. \args{ Obj, Ptr : Oop }
  107. \ext{ \Wr OM : \mapof{Oop}{Basic_Object} }
  108. \pre{ ptr \in  \elems{BODY(om(obj))} }
  109. \post{ om = ~{om} \owr \map{ obj \mapsto 
  110.         \chg{om(obj)}{BODY}{BODY \diff \set{ptr}}}}
  111. \end{op}
  112. \end{vdm}
  113.  
  114. % this is verbatim input
  115. \begin{verbatim}
  116. \begin{vdm}
  117. \begin{fn}{dec}{ptrs,om} \\
  118. \signature{
  119.       \setof{Oop} \x \mapof{Oop}{Object} \to \mapof{Oop}{Object} 
  120. }
  121. \If ptrs = \emptyset
  122. \Then om
  123. \Else   \Let gone = \set{p \in ptrs | RC(om(p)) = 1} \In
  124.         \Let om' = gone \dsub om \In
  125.         \Let om'' = om' \owr
  126.                 \map{p \mapsto \chg{om'(p)}{RC}{RC\minus 1}
  127.                         | p \in ptrs \diff gone} \In
  128.         dec(\Union\set{\elems{BODY(om(p))} | p \in gone}, om'')
  129. \Fi
  130. \end{fn}
  131.  
  132. \begin{op}[DESTROYPTR]
  133. \args{ Obj, Ptr : Oop }
  134. \ext{ \Wr OM : \mapof{Oop}{Basic_Object} }
  135. \pre{ ptr \in  \elems{BODY(om(obj))} }
  136. \post{ om = ~{om} \owr \map{ obj \mapsto 
  137.                 \chg{om(obj)}{BODY}{BODY \diff \set{ptr}}}}
  138. \end{op}
  139. \end{vdm}
  140.  
  141. \end{verbatim}
  142.  
  143. \noindent
  144. Impressed, huh?  Read on...
  145.  
  146.  
  147. \section*{Using \Vdm---General Points}
  148.  
  149. To get at \Vdm, include {\tt vdm\/} as a document style option, e.g.:
  150. \begin{verbatim}
  151.         \documentstyle[12pt,vdm]{report}
  152. \end{verbatim}
  153. \begin{dangerous}
  154. To the best of my knowledge, the use of \Vdm\ does not conflict with
  155. any of the other document styles, except when something has been
  156. redefined.   An attempt will be made to document all such redefinitions.
  157. \end{dangerous}
  158. Once \Vdm\ has been included, you can then use the {\tt vdm\/}
  159. environment.  For example,
  160. \begin{verbatim}
  161.          \begin{vdm}
  162.             ....
  163.          \end{vdm}
  164. \end{verbatim}
  165. All specification material should be placed within the {\tt vdm\/}
  166. environment.  The use of \Vdm\ only affects text within the {\tt vdm\/}
  167. environment, except for the following global changes (which are only
  168. relevant when in math or display math mode):
  169. \begin{enumerate}
  170. \item    The mathcodes of a\dots z and A\dots Z have been changed.  In
  171.     plain English, this means that when you type letters in math
  172.     mode the inter-letter spacing is different than it would be
  173.     had you not included \Vdm\ as an option.\footnote{This is not
  174.     the case if you are using PS\LaTeX.}  This is because
  175.     \LaTeX\ math mode is usually tuned for single letter
  176.     identifiers, as used by mathematicians for millenia.  However,
  177.     you and I both know that most meaningful identifiers have more
  178.     than one letter in them, so \Vdm\ provides better spacing for
  179.     them.  As an example, if you type \verb;$identifier$;, \LaTeX\
  180.     would normally print {\defaultMathcodes$identifier$}, whereas
  181.     the use of \Vdm\ will yield $identifier$.
  182.     \begin{dangerous}\indent If you really want to use the
  183.     `normal' inter-letter spacing, say \cs\defaultMathcodes.
  184.     \end{dangerous}
  185. \item    Underscore gives you an underscore, and not a subscript.  If
  186.     you want a subscript use \verb;@;, e.g.,~$x@0$ is typed
  187.     \verb;x@0;, or use \TeX's \cs\sb\ macro.  An \verb;@; is still an
  188.     @ when not in math mode.  Occasionally you may find that an @
  189.     in math mode {\em doesn't\/} give you a subscript.  Should
  190.     this happen, you are advised to use \TeX's \cs\sb\ macro,
  191.     e.g.,~\verb;$x\sb0$;. 
  192.     \begin{dangerous}
  193.     \indent If you don't use
  194.     underscores much, and you want to use \verb;_; for subscripts,
  195.     you can say \cs\underscoreon\ (and \cs\underscoreoff\ to
  196.     make it revert to its usual meaning in \Vdm).
  197.     \end{dangerous}
  198. \item    \verb;-; typesets a hyphen, and not a minus sign.  VDM specifications
  199.     usually contain a lot more
  200.     \begin{vdm}$long-identifiers$\end{vdm} than subtractions, so
  201.     on the whole this alteration should save effort.  If you really want
  202.     to do a subtraction, use \cs\minus.
  203. \item    \verb;|; gives you a \begin{vdm}$|$\end{vdm}, and not a $\vert$.
  204.     Do you see the difference?  No?  The former goes between things,
  205.     e.g., \begin{vdm}$\set{x|p(x)}$\end{vdm}, while the latter is
  206.     a delimiter, e.g.,~$|x|$.
  207.     Most people use the former more than the latter, so again this
  208.     seems reasonable.  If you really want a $|$ (the second kind),
  209.     say \cs\vert. 
  210. \item    In \TeX\ and \LaTeX\ \verb;~; has always been a tie.  Well
  211.     in \Vdm\ it isn't.  \verb;~x; will give you a
  212.     \begin{vdm}$~x$\end{vdm}.  For long identifiers, such as
  213.     \begin{vdm}$~{long}$\end{vdm}, say
  214.     \verb;~{long};.  {\em Note that this only applies in math
  215.     mode; elsewhere a \verb;~; is still a tie.} 
  216. \item    In math mode, the double quote character \verb;"; is actually
  217.     a macro.  Placing text between pairs of double quotes causes
  218.     that text to be set in the normal text font.  For example,
  219.     \verb;$x="a variable"$; gives you $x="a variable"$.  
  220.     \begin{dangerous}
  221.     \indent If you want to change the font used for text placed between
  222.     quotes, redefine the command \cs\mathTextFont.  By default
  223.     it is defined to be \cs\rm.
  224.     \end{dangerous}
  225. \item    The following macros have been altered in a non-trivial way:
  226.     \cs\forall, \cs\exists.
  227. \end{enumerate}
  228.  
  229. \begin{dangerous}
  230. When you typeset some VDM within the {\tt vdm\/} environment, by
  231. default it is set in from the left margin by an amount equal to
  232. \cs\parindent, the indentation at the beginning of each paragraph.
  233. If you want to change this, change the value of \cs\VDMindent, e.g.:
  234. \begin{verbatim}
  235.         \setlength{\VDMindent}{0cm}
  236. \end{verbatim}
  237. will make your specs come out flush left.  This document has been
  238. typeset with \cs\VDMindent\ equal to $3\times \cs\parindent$.
  239.  
  240. Similarly, the right hand margin is controlled by a parameter called
  241. \cs\VDMrindent.  By default it is also set to \cs\parindent.
  242. \end{dangerous}
  243.  
  244. \begin{dangerous}
  245. Similarly, you can have a particular line spacing in force within the
  246. {\tt vdm} environment.
  247. %  However, you have to tread carefully here.
  248. %\TeX\ {\em always\/} enforces a single line spacing within a
  249. %particular paragraph, and the value used is the value current at the
  250. %{\em end\/} of the paragraph.  So to make the material within a {\tt
  251. %vdm} environment have a different spacing from that surrounding it,
  252. %you must always put it in a separate paragraph, by placing a blank
  253. %line before and after it, otherwise strange things will happen.  
  254. The spacing within a {\tt vdm} environment is dictated by the
  255. \cs\VDMbaselineskip\ command.  Note that this is {\em not\/} a
  256. length, but a command.  By default it expands to \cs\baselineskip\
  257. so that the line spacing is that of the surrounding text, whatever 
  258. size that may be.  To make it smaller, you may want to say
  259. \begin{verbatim}
  260.     \renewcommand{\VDMbaselineskip}{0.8\baselineskip}
  261. \end{verbatim}
  262. for example.
  263. \end{dangerous}
  264.  
  265.  
  266. \section*{Typesetting formulas}
  267.  
  268. Most of the text you enter within {\tt vdm\/} environments will be in
  269. \TeX's math mode, but VDM does its best to conceal this fact from you,
  270. so that you should rarely, if ever, have to type a dollar sign.
  271. However, several new features have been provided for the typesetting
  272. of logical formulas.  Firstly, operators with sensible names have been
  273. provided: use \cs\Iff, \cs\Implies, \cs\Or, \cs\And\
  274. and \cs\Not\ for the operators~\begin{vdm}%
  275. $\Iff,\Implies,\Or,\And,\Not$\end{vdm}.
  276. (To retain compatibility with a previous version, \cs\iff,
  277. \cs\implies, \cs\and\ and \cs\neg\ are still provided, but
  278. \cs\or\ is not.)
  279.  
  280. A major change has come in the area of quantified expressions.  They
  281. have very well-defined forms, so the \LaTeX\ sequences \cs\forall\
  282. and \cs\exists\ have been re-defined to take arguments.  For
  283. example, to get
  284. \begin{vdm}
  285. \begin{formula}
  286. \exists{x \in S}{p(x)}
  287. \end{formula}
  288. \end{vdm}
  289. \noindent type
  290. \begin{verbatim}
  291.         \exists{x \in S}{p(x)}
  292. \end{verbatim}
  293. Note the separating dot that was put in auto\-matically.  If you want
  294. one of these dots by itself, you can have one by saying
  295. \cs\suchthat.
  296.  
  297. In addition, two new quantifiers, \cs\unique\ and \cs\nexists, have
  298. been added: 
  299.  
  300. \begin{leftside}
  301. \begin{formula}
  302. \unique{x \in S}{p(x)}
  303. \end{formula}
  304. \begin{formula}
  305. \nexists{x \in S}{p(x)}
  306. \end{formula}
  307. \end{leftside}\begin{rightside}
  308. \unique{x \in S}{p(x)}
  309. \nexists{x \in S}{p(x)}
  310. \end{verbatim}\end{rightside}
  311.  
  312. Additionally, to complement \cs\unique, there is \cs\uniqueval.  This
  313. is the so-called ``iota-function'' that returns the unique value, if
  314. there is one:
  315.  
  316. \begin{leftside}
  317. \begin{formula}
  318. \uniqueval{x \in S}{p(x)}
  319. \end{formula}
  320. \end{leftside}\begin{rightside}
  321. \uniqueval{x \in S}{p(x)}
  322. \end{verbatim}\end{rightside}
  323.  
  324.  
  325. \begin{dangerous}
  326. If you want to use the old versions of \cs\forall\ and
  327. \cs\exists\ they are available under the pseudonyms of
  328. \cs\Forall\ and \cs\Exists.
  329. \end{dangerous}
  330.  
  331. If you find that the body of the quantified expression is too long to
  332. fit comfortably on a line, there are *-forms of the above commands
  333. that place the body of the quantified expression on a new line,
  334. slightly indented.  For example,
  335.  
  336. \begin{vdm}
  337. \begin{formula}
  338. \exists*{x \in S}{
  339.     p(x) \And q(x) \Or \Not p(x) \Implies r(x) \And S(x)}
  340. \end{formula}
  341. \end{vdm}
  342.  
  343. \noindent can be obtained with
  344. \begin{verbatim}
  345.       \exists*{x \in S}{p(x) \And q(x) \Or \Not p(x)
  346.                         \Implies r(x) \And S(x)}
  347. \end{verbatim}
  348.  
  349. If you need ``Strachey'' brackets, e.g., $M\term{e}$, place the
  350. material to appear within the brackets within \verb;\term{ ... };,
  351. thus: \verb;$M\term{e}$;.
  352.  
  353. A special control sequence, \cs\const, is available for constants.
  354. To get, for example, $\const{Yes}|\const{No}$, type
  355. \verb;\const{Yes}|\const{No};.
  356. \begin{dangerous}
  357. If you don't like the font that constants are set in, you can change
  358. them by redefining the command \cs\constantFont.  By
  359. default it expands to \cs\sc.
  360. \end{dangerous}
  361.  
  362. \subsection*{The {\tt formula} Environment}
  363.  
  364. Occasionally you may want a formula on its own, between paragraphs of
  365. text, say.  Normally, the provided environments and commands suffice,
  366. but sometimes they don't.  If you need an odd equation to stand on its
  367. own, use the {\tt formula} environment:
  368. \begin{verbatim}
  369.        \begin{formula}
  370.        x = 10
  371.        \Or  \forall{i \in \Nat}{i \ne 10 \Implies i \ne x}
  372.        \end{formula}
  373. \end{verbatim}
  374. \sloppy
  375. The {\tt formula} environment is similar to displayed math mode,
  376. except: formulas are indented by \cs\VDMindent, not
  377. \cs\mathindent, and line breaks can be made using \cs\\.
  378. Also, within the {\tt formula} environment everything appears flush
  379. left, as opposed to being centred. 
  380.  
  381. \subsection*{Constructions}
  382.  
  383. A particularly nice feature of \Vdm\ is that you can typeset multi-line
  384. constructions such as those in the earlier example without having to
  385. worry about, say, lining up ``thens'' and ``elses'' with ``ifs''.
  386. In the following definitions, whenever you see the term \mmexp, you
  387. should type an expression as if in math mode, but you needn't put
  388. dollar signs in.  All of the constructions described below can be used
  389. where a \mmexp\ is required.  Each construction is shown by example;
  390. the output on the left results from the input on the right.
  391. Also note that each macro name begins with an upper-case letter.
  392. \TeX\ and \LaTeX\ frequently use the lower-case variants for
  393. completely unrelated things.  Naturally, chaos will ensue if you mix
  394. the names up.
  395.  
  396. Typesetting an \kw{if} is done using \cs\If\ \mmexp \cs\Then\ \mmexp
  397. \cs\Else\ \mmexp \cs\Fi.
  398.  
  399. \begin{leftside}
  400.   \begin{formula}
  401.     \If x\in S
  402.     \Then S \diff x
  403.     \Else \emptyset
  404.     \Fi
  405.   \end{formula}
  406. \end{leftside}%
  407. \begin{rightside}
  408. \If x\in S
  409. \Then S \diff x
  410. \Else \emptyset
  411. \Fi
  412. \end{verbatim}
  413. \end{rightside}
  414.  
  415. If you nest \cs\If{}s then you must enclose inner \cs\If{}s within
  416. braces:
  417.  
  418. \begin{leftside}
  419.   \begin{formula}
  420.         \If \ldots
  421.         \Then{
  422.                 \If \ldots
  423.                 \Then \ldots
  424.                 \Else \ldots
  425.                 \Fi
  426.         }\Else
  427.         \Fi
  428.   \end{formula}
  429. \end{leftside}\begin{rightside}
  430. \If ... 
  431. \Then{
  432.         \If ...
  433.         \Then ...
  434.         \Else ...
  435.         \Fi
  436. }\Else
  437. \Fi
  438. \end{verbatim}\end{rightside}
  439.  
  440. You are advised to place the extra braces exactly as above; don't let
  441. extraneous spaces intervene between the keywords and the braces.
  442.  
  443. The \cs\If\ macro always starts a new line for the \kw{then} and
  444. \kw{else} parts.  If you want \TeX\ to try to choose line breaks, use
  445. \cs\SIf\ instead:
  446.  
  447. \begin{leftside}
  448.   \begin{formula}
  449.     \SIf a=b
  450.     \Then c=d+e
  451.     \Else p=q+r+s+t+u
  452.     \Fi
  453.   \end{formula}
  454. \end{leftside}%
  455. \begin{rightside}
  456. \SIf a=b
  457. \Then c=d+e
  458. \Else p=q+r+s+t+u
  459. \Fi
  460. \end{verbatim}
  461. \end{rightside}
  462.  
  463. \mbox{\kw{let}\dots\kw{in}} constructions are done in a similar way:
  464. \cs\Let{} \mmexp{} \cs\In{} \mmexp, and \cs\SLet{} \mmexp{} 
  465. \cs\In{} \mmexp. 
  466.  
  467. \begin{leftside}
  468.   \begin{formula}
  469.     \Let x=f(y,z) \In
  470.     g(x)+h(x)
  471.   \end{formula}
  472. \end{leftside}%
  473. \begin{rightside}
  474. \Let x=f(y,z) \In
  475. g(x)+h(x)
  476. \end{verbatim}
  477. \end{rightside}
  478.  
  479. \begin{leftside}
  480.   \begin{formula}
  481.     \SLet x=f(y,z) \In{
  482.       g(x)+h(x)
  483.     }
  484.   \end{formula}
  485. \end{leftside}%
  486. \begin{rightside}
  487. \SLet x=f(y,z) \In{
  488. g(x)+h(x)
  489. }
  490. \end{verbatim}
  491. \end{rightside}
  492.  
  493. Notice that \cs\SLet\ takes a second argument, which is part of the
  494. same `paragraph', where \cs\Let\ does not.
  495.  
  496. The typesetting of a \kw{cases} clause is more complicated.  It takes
  497. the form:
  498. \begin{verse}
  499. \verb;\Cases{; \mmexp \verb;}; \\
  500. from-\mmexp \verb;&; to-\mmexp \cs\\ \\
  501. from-\mmexp \verb;&; to-\mmexp \cs\\ \\
  502. \dots \\
  503. \verb;\Otherwise{; \mmexp \verb;}; \\
  504. \verb;\Endcases;
  505. \end{verse}
  506.  
  507. The \cs\Otherwise\ field is optional.  This construction follows a
  508. general pattern that is common in \Vdm\ input:  lists of things are
  509. separated by \cs\\s, and subfields are separated by \verb;&;s or
  510. \verb;:;s. 
  511. \begin{dangerous}
  512. In reality, there is another, optional argument, after the
  513. \cs\Endcases.  If you were to try typesetting something like
  514. \begin{verbatim}
  515.         (... var = \Cases ...
  516.                    \Endcases)
  517. \end{verbatim}
  518. you'd find the closing right parenthesis in an unexpected place (on
  519. the same line as the $=$, in fact).  To get text to the right of the
  520. \cs\Endcases\ you can place an optional argument within brackets
  521. after it:
  522. \begin{verbatim}
  523.         (... var = \Cases ...
  524.                    \Endcases[)]
  525. \end{verbatim}
  526. Admittedly, this looks a little strange, but it does work.
  527. \end{dangerous}
  528.  
  529. Here is an example of \cs\Cases\ in action:
  530.  
  531. \begin{formula}
  532.   \Cases{ select(x) }
  533.   \nil            & \emptyset \\
  534.   mk-Lst(hd,tl)  & \set{hd} \union elems(tl)
  535.   \Otherwise{ x }
  536.   \Endcases
  537. \end{formula}
  538.  
  539. \begin{verbatim}
  540.      \Cases{ select(x) }
  541.      \nil            & \emptyset \\
  542.      mk-Lst(hd,tl)  & \set{hd} \union elems(tl)
  543.      \Otherwise{ x }
  544.      \Endcases
  545. \end{verbatim}
  546.  
  547. Note the \cs\\ is a {\em separator\/} and not a {\em
  548. terminator\/}---you don't need one after the last item.  Also, the
  549. \cs\Otherwise\ can appear anywhere between the \verb;\Cases{}; and the
  550. \cs\Endcases, but it will always be typeset last.
  551. \begin{dangerous}
  552. Some people prefer the selectors to appear lined up on the left, some
  553. on the right.  If you want them to appear on the left, say
  554. \cs\leftCases; if you want them on the right, say
  555. \cs\rightCases.  The scope of the \cs\leftCases\ and
  556. \cs\rightCases\ commands is the current group.  By default, you
  557. get \cs\rightCases.
  558. \end{dangerous}
  559.  
  560. \subsubsection*{The {\tt formbox} Environment}
  561.  
  562. Occasionally you might find that you want to put a line break in a
  563. place that can't handle \cs\\.  For example, if you have a \cs\Cases\
  564. command and the rhs of a particular case is too big, you can't use
  565. \cs\\ to break the line directly, as it will be interpreted as the
  566. separator between cases.  Then you must the {\tt formbox} environment.
  567. It is similar to the {\tt formula} environment in that you can put all
  568. sorts of things in it, but it can be used within other constructions,
  569. unlike the {\tt formula} environment, which can only be used at the
  570. outermost level.
  571.  
  572. This example should convey the general idea:
  573. \begin{verbatim}
  574.         \Cases{ f(x) }
  575.         mk-Very_long_constructor(foo,bar) &
  576.             {\begin{formbox}
  577.             long_predicate_with(foo) \\
  578.               \And long_predicate_with(bar)
  579.             \end{formbox}}
  580.         ...
  581. \end{verbatim}
  582. \begin{formula}
  583.         \Cases{ f(x) }
  584.         mk-Very_long_constructor(foo,bar) &
  585.             {\begin{formbox}
  586.             long_predicate_with(foo) \\
  587.               \And long_predicate_with(bar)
  588.             \end{formbox}}
  589.         \ldots
  590.     \Endcases
  591. \end{formula}
  592. Note the extras braces around the {\tt formbox}; these are required to
  593. ``hide'' the \cs\\ from the \cs\Cases.
  594.  
  595. \subsection*{Other General Points about Formulas}
  596.  
  597. \cs\\ will%
  598. \footnote{For `will' read `should'.} 
  599. {\em always\/}
  600. start a new line.  Sometimes this is done in addition to some other
  601. function (as in the \cs\Cases\ macro, where it delimits a
  602. particular case), but you should be able to use \cs\\ almost
  603. anywhere to force a line break.  Indeed, sooner or later you'll want
  604. to typeset a long formula and \TeX\ will not be able to break the line
  605. sensibly, or will choose an unpleasant break.  In this case you'll
  606. have to use \cs\\.
  607.  
  608. Frequently you need to indent things within multi-line formulas.  To
  609. help you do this, a command is provided which breaks a line, and
  610. indents the next line by an amount which you can supply (in units of
  611. {\tt ems}).  The \cs\T\ command takes a single argument that controls
  612. how much the next line will be indented:
  613.  
  614. \begin{leftside}
  615. \begin{formula}
  616. a \And b \T2
  617. \Implies b \And a \T1
  618. \Or d \And e
  619. \end{formula}
  620. \end{leftside}\begin{rightside}
  621. a \And b \T2
  622. \Implies b \And a \T1
  623. \Or d \And e
  624. \end{verbatim}\end{rightside}
  625.  
  626. Along similar lines is the \cs\R\ command.  This does a line break,
  627. like \cs\\, but then pushes the formula on the next line as far to the
  628. right as it can:
  629. \begin{leftside}
  630. \begin{formula}
  631. (a \And b \Implies b \And a) \R
  632. \Or d \And e
  633. \end{formula}
  634. \end{leftside}\begin{rightside}
  635. (a \And b \Implies b \And a) \R
  636. \Or d \And e
  637. \end{verbatim}\end{rightside}
  638.  
  639. Beware: it may end up pushing it further to the right than you
  640. expected!  This is {\sc A Bug}, and {\sc Will Not Be Fixed}, so you'll
  641. have to work around it.
  642.  
  643. The \cs\If, \cs\Let, etc., constructions are all unusual in
  644. that it's impossible to typeset something sensibly to the right of
  645. them.  For example, if you try
  646. \begin{verbatim}
  647.         \exists{x \in S}{
  648.            \If x=0 \Then S=Q \Else S=P \Fi}
  649.         \Or S=\emptyset
  650. \end{verbatim}
  651. then you'll get
  652.  
  653. \begin{vdm}
  654.   \begin{formula}
  655.     \exists{x \in S}{\If x=0 \Then S=Q \Else S=P \Fi} \Or S=\emptyset
  656.   \end{formula}
  657. \end{vdm}
  658.  
  659. \noindent which is unlikely to be what you wanted.
  660.  
  661. You should also remember that where \Vdm\ wants a \mmexp, \TeX\ will
  662. be placed in math mode.  This is usually the right thing to do, but
  663. occasionally you might want a natural language comment to appear
  664. there.
  665. In this case you'll have to insert an \cs\mbox\ or a \cs\parbox\
  666. depending on whether your comment might span one or more lines:
  667.  
  668. \begin{leftside}
  669.   \begin{formula}
  670.     \If \mbox{the condition is true}
  671.     \Then \mbox{do the true part}
  672.     \Else "do the false part"
  673.     \Fi
  674.   \end{formula}
  675. \end{leftside}%
  676. \begin{rightside}
  677. \If \mbox{the condition is true}
  678. \Then \mbox{do the true part}
  679. \Else "do the false part"
  680. \Fi
  681. \end{verbatim}\end{rightside}
  682. The else-part illustrates how quotes can be used an an abbreviation
  683. for \verb;\mbox{...}; within math mode.
  684.  
  685. Finally, all the constructions above will not break at a page
  686. boundary.  This means that you're in big trouble if you want to
  687. typeset a three-page \cs\Cases.  The only statement I can make to
  688. mitigate this is: you shouldn't have expressions that complicated in
  689. the first place---who do you expect to read them?  Remember: ``truth
  690. is beauty'', so if your formulas are not beautiful, then chances are
  691. they're not true either.
  692.  
  693.  
  694.  
  695.  
  696.  
  697. \section*{Typesetting data types}
  698.  
  699. The following table lists the primitive types and values available:
  700.  
  701. \begin{center}
  702. \begin{tabular}{|l|l|l|}
  703. \hline
  704. $\set{0,1,\dots}$    & $\Nat$    & \cs\Nat     \\
  705. $\set{1,2,\dots}$    & $\Natone$    & \cs\Natone,\cs\Nati    \\
  706. $\set{\dots,\minus1,0,1,\dots}$& $\Int$    & \cs\Int    \\
  707. Rationals        & $\Rat$    & \cs\Rat    \\
  708. Real numbers        & $\Real$    & \cs\Real    \\
  709. $\set{\true,\false}$    & $\Bool$    & \cs\Bool    \\
  710. Truth            & $\true$    & \cs\true,\cs\True \\
  711. Falsehood        & $\false$    & \cs\false,\cs\False\\
  712. Nil            & $\nil$    & \cs\nil    \\
  713. \hline
  714. \end{tabular}
  715. \end{center}
  716.  
  717. If you need a new keyword, you can create one easily.  For example, if
  718. your favourite brand of logic has ``maybe'' as a value, you can say
  719. \begin{verbatim}
  720.         \makeNewKeyword{\maybe}{maybe}
  721. \end{verbatim}
  722. and henceforth \cs\maybe\ is a valid control sequence that produces
  723. the text \kw{maybe}.  The text of the second argument to
  724. \cs\makeNewKeyword\ can be anything; it doesn't have to match your
  725. control sequence name.
  726. \begin{dangerous}
  727. If you don't like the font that keywords are set in, you can change
  728. it by redefining the command \cs\keywordFontBeginSequence.  By
  729. default it expands to \cs\small\cs\sf.
  730. \end{dangerous}
  731.  
  732. The following type-related commands are provided:
  733.  
  734. \begin{center}
  735. \begin{tabular}{|l|l|l|}
  736. \hline
  737. Output        & Input            & \\
  738. \hline
  739. $\setof{x}$    & \verb;\setof{x};    & set type constructor \\
  740. $\set{a,b,c}$    & \verb;\set{a,b,c};    & set enumeration \\
  741. $\emptyset$    & \cs\emptyset        & the empty set \\
  742. $\seqof{x}$    & \verb;\seqof{x};    & seq. type constructor\\
  743. $\seq{a,b,a,c}$    & \verb;\seq{a,b,a,c};    & seq. enumeration\\
  744. $\emptyseq$    & \cs\emptyseq    & the empty sequence \\
  745. $\mapof{x}{y}$    & \verb;\mapof{x}{y};    & map type constructor \\
  746. $\mapinto{x}{y}$& \verb;\mapinto{x}{y};    & one-one map type \\
  747. $\map{p\mapsto x}$
  748.         & \verb;\map{p\mapsto x}; & map enumeration\\
  749. $\emptymap$    & \cs\emptymap    & the empty map \\
  750. \hline
  751. \end{tabular}
  752. \end{center}
  753.  
  754. \noindent Here are the relevant operators:
  755.  
  756. \begin{center}\small
  757. \begin{tabular}{llllll}
  758. $\in$        & \cs\in    &
  759.     $\owr$    & \cs\owr    &
  760.         $\sconc$    & \cs\sconc    \\
  761. $\notin$    & \cs\notin    &
  762.     $\dres$    & \cs\dres    &
  763.         $\len{l}$    & \verb;\len{l};\\
  764. $\subset$    & \cs\subset&
  765.     $\rres$    & \cs\rres    &
  766.         $\hd{l}$    & \verb;\hd{l};    \\
  767. $\subseteq$    & \cs\subseteq&
  768.     $\dsub$    & \cs\dsub    &
  769.         $\tl{l}$    & \verb;\tl{l};    \\
  770. $\inter$    & \cs\inter,\cs\intersection;&
  771.     $\rsub$    & \cs\rsub    &
  772.         $\elems{l}$    & \verb;\elems{l};\\
  773. $\Inter$    & \cs\Inter,\cs\Intersection;&
  774.     $\dom{m}$&\verb;\dom{m};&
  775.         $\inds{l}$    & \verb;\inds{l};\\
  776. $\union$    & \cs\union    &
  777.     $\rng{m}$&\verb;\rng{m};&
  778.         $\Conc{l}$    & \verb;\Conc{l};\\
  779. $\Union$    & \cs\Union    &
  780.     $\Min{s}$& \verb;\Min{s};&
  781.         $\cons{h,t}$    & \verb;\cons{h,t};\\
  782. $\diff$        & \cs\diff,\cs\difference;&
  783.     $\Max{s}$& \verb;\Max{s};&    
  784.                 &    \\
  785. $\card{s}$    & \verb;\card{s};&
  786.         &        &
  787.                 &
  788. \end{tabular}
  789. \end{center}
  790.  
  791. \noindent
  792. (\inds{} and \elems{} are not, strictly speaking, part of VDM any
  793. more; use \dom{} and \rng{}.)
  794.  
  795. \begin{dangerous}
  796. If you invent a new monadic keyword operator (like \dom{}, etc.),
  797. then you can have \Vdm\ define for you a control sequence which
  798. switches font, and puts the right spacing in.  For example,
  799. \begin{verbatim}
  800.         \newMonadicOperator{\inv}{inv}
  801. \end{verbatim}
  802. will define the \cs\inv\ control sequence to print
  803. {\keywordFontBeginSequence inv\/}.  Henceforth you can say, e.g.,
  804. \verb;\inv{Foo};.  All such sequences take one argument (they are
  805. monadic, after all).
  806. \end{dangerous}
  807.  
  808. You can define a new type using
  809. \verb;\type{;type-name\verb;}{;type\verb;};:
  810.  
  811. \begin{leftside}
  812.   \type{Complex}{\Real\x \Real}
  813. \end{leftside}%
  814. \begin{rightside}
  815. \type{Complex}{\Real\x \Real}
  816. \end{verbatim}\end{rightside}
  817.  
  818. Composites types can be typeset using the {\tt composite} environment:
  819.  
  820. \begin{leftside}
  821.   \begin{composite}{Datec}
  822.     day:\set{1,\ldots,366}, \\
  823.     year:\set{1583,\ldots,2599}
  824.   \end{composite}
  825. \end{leftside}%
  826. \begin{rightside}
  827. \begin{composite}{Datec}
  828.   day :\set{1,\ldots,366}, \\
  829.   year:\set{1583,\ldots,2599}
  830. \end{composite}
  831. \end{verbatim}\end{rightside}
  832.  
  833. There is also a {\tt composite*} environment (and an equivalent
  834. \cs\scompose\ control sequence) that places the entire composite
  835. type on a single line:
  836.  
  837. \begin{leftside}
  838.   \begin{composite*}{Celsius}
  839.     \Real
  840.   \end{composite*}
  841. \end{leftside}%
  842. \begin{rightside}
  843. \begin{composite*}{Celsius}
  844.   \Real
  845. \end{composite*}
  846. \end{verbatim}\end{rightside}
  847.  
  848. \begin{leftside}
  849.   \scompose{Celsius}{\Real}
  850. \end{leftside}%
  851. \begin{rightside}
  852. \scompose{Celsius}{\Real}
  853. \end{verbatim}\end{rightside}
  854.  
  855. `Records' can be defined using the {\tt record\/} environment:
  856.  
  857. \begin{verse}
  858. \verb;\begin{record}{;record-type-name\verb;}; \\
  859. field-name \verb;:; field-type \cs\\ \\
  860. \dots \\
  861. \verb;\end{record};
  862. \end{verse}
  863. The colons are used as sub-field separators.
  864.  
  865. \begin{leftside}
  866.   \begin{record}{PERSON}
  867.     NM : \seqof{Char} \\
  868.     FEM : \Bool
  869.   \end{record}
  870. \end{leftside}%
  871. \begin{rightside}
  872.     \begin{record}{PERSON}
  873.       NM : \seqof{Char} \\
  874.       FEM : \Bool
  875.     \end{record}
  876. \end{verbatim}\end{rightside}
  877.  
  878. If the definition is short, you may prefer to use a short form:
  879. \begin{verbatim}
  880.         \defrecord{PERSON}{
  881.           NM : \seqof{Char} \\
  882.           FEM : \Bool
  883.         }
  884. \end{verbatim}
  885.  
  886. \begin{dangerous}
  887. Some people prefer the field names to appear lined up on the left, some
  888. on the right.  If you want them to appear on the left, say
  889. \cs\leftRecord; if you want them on the right, say
  890. \cs\rightRecord.  The scope of the \cs\leftRecord\ and
  891. \cs\rightRecord\ commands are the current group.  By default, you
  892. get \cs\rightRecord.
  893. \end{dangerous}
  894.  
  895. Updating fields of composites using the $\mu$-function can be
  896. specified using \cs\chg:
  897.  
  898. \begin{leftside}
  899.   \begin{formula}
  900.     \chg{p}{FEM}{\Not man(q)}
  901.   \end{formula}
  902. \end{leftside}%
  903. \begin{rightside}
  904. \chg{p}{FEM}{\Not man(q)}
  905. \end{verbatim}\end{rightside}
  906.  
  907. Notice that the $\mu$, parentheses, comma and $\mapsto$ were inserted
  908. automatically.
  909.  
  910.  
  911.  
  912. \section*{How to Typeset Functions}
  913.  
  914. Typesetting $\lambda$-expressions is easy:
  915.  
  916. \begin{leftside}
  917.   \begin{formula}
  918.     \LambdaFn{x,y}{x^2+y^2}
  919.   \end{formula}
  920. \end{leftside}%
  921. \begin{rightside}
  922. \LambdaFn{x,y}{x^2+y^2}
  923. \end{verbatim}\end{rightside}
  924.  
  925. As with \cs\forall, \cs\exists\ and \cs\unique,
  926. \cs\LamdbaFn\ has a *-form that places the body of the function
  927. below and to the right:
  928.  
  929. \begin{leftside}
  930.   \begin{formula}
  931.     \LambdaFn*{x,y,z}{
  932.       (x^2+y^2+z^2)^{\frac12}}
  933.   \end{formula}
  934. \end{leftside}%
  935. \begin{rightside}
  936. \LambdaFn*{x,y,z}{
  937.   (x^2+y^2+z^2)^{\frac12}}
  938. \end{verbatim}\end{rightside}
  939.  
  940. There is also a {\tt fn\/} (function) environment for defining named
  941. functions.  It has the following structure:
  942. \begin{verse}
  943. \verb;\begin{fn}{;name-of-function\verb;}{; argument-list \verb;}; \\
  944. \verb;\signature{;signature-of-function\verb;}; \\
  945. \^{optional precondition}\\
  946. \^{optional postcondition}\\
  947.  body of function (a \mmexp) \\
  948. \verb;\end{fn};
  949. \end{verse}
  950.  
  951. See the first page for an example.  The \cs\signature\ is optional
  952. and can be placed anywhere within the body---it will always be typeset
  953. before the body.  Useful macros within the \cs\signature\ are:
  954. \cs\x\ and \cs\to, which yield $\x$ and~$\to$.  Note that you can also
  955. enter functions defined implicitly with pre- and post-conditions; see the
  956. next section on how to enter them.
  957.  
  958. All of the material in the section on formulas is relevant within the
  959. body of the function.
  960.  
  961. \sloppy\sloppy
  962. If you frequently intersperse your function definitions with text (and you
  963. should), you can save some typing by using the {\tt vdmfn\/} environment.
  964. \cs\begin\verb;{vdmfn}; \dots \cs\end\verb;{vdmfn}; is equivalent to
  965. \cs\begin\verb;{vdm};\cs\begin\verb;{fn}; \dots
  966. \cs\end\verb;{fn};\cs\end\verb;{vdm};.
  967.  
  968. The {\tt fn} environment also has a *-form that omits inserting
  969. parentheses around the argument list.  For example:
  970.  
  971.  
  972. \begin{leftside}
  973. \begin{fn*}{MP}{\term{p}\rho\sigma}
  974. \ldots
  975. \end{fn*}
  976. \end{leftside}\begin{rightside}
  977. \begin{fn*}{MP}{
  978.   \term{p}\rho\sigma}
  979. ...
  980. \end{fn*}
  981. \end{verbatim}\end{rightside}
  982.  
  983. If you require the $\DEF$ symbol by itself (for example, in a
  984. footnote), then you can get it by saying \cs\DEF.
  985.  
  986. \subsection*{Invariants}
  987.  
  988. To typeset an invariant on a composite object, use the following
  989. structure:
  990.  
  991. \begin{leftside}
  992. \begin{record}{D}
  993.   day : Day \\
  994.   year : Year
  995. \end{record}
  996. \where
  997. \begin{fn}{inv-D}{mk-D(d,y)}
  998.   is-leapyr(y) \Or d \le 365
  999. \end{fn}
  1000. \end{leftside}\begin{rightside}
  1001. \begin{record}{D}
  1002.   day : Day \\
  1003.   year : Year
  1004. \end{record}
  1005. \where
  1006. \begin{fn}{inv-D}{mk-D(d,y)}
  1007.   is-leapyr(y) \Or d \le 365
  1008. \end{fn}
  1009. \end{verbatim}\end{rightside}
  1010.  
  1011.  
  1012. \section*{How to Typeset Operations}
  1013.  
  1014. Operations are typeset within the {\tt op\/} environment.
  1015. The general structure is:
  1016.  
  1017. \begin{verse}
  1018. \verb;\begin{op}[;\^{name-of-operation}\verb;]; \\
  1019. \verb;\args{;\^{list-of-arguments}\verb;}; \\
  1020. \verb;\res{;\^{result(s)}\verb;}; \\
  1021. \verb;\ext{;\^{list-of-externals}\verb;}; \\
  1022. \^{pre-condition} \\
  1023. \^{post-condition} \\
  1024. \verb;\end{op};
  1025. \end{verse}
  1026.  
  1027. The order of the various parts within the {\tt op} environment is not
  1028. important; they will always be printed in a canonical style (see
  1029. page~\pageref{op-ex} for an example).
  1030.  
  1031. Any of \cs\args, \cs\res, \cs\ext, \^{pre-condition} or
  1032. \^{post-condition} may be omitted.  \verb;\begin{vdmop}; is an
  1033. abbreviation for \verb;\begin{vdm}\begin{op};;  \verb;\end{vdmop}; is an
  1034. abbreviation for \verb;\end{op}\end{vdm};.
  1035.  
  1036. The \^{name-of-operation} can be any one-line expression; it is
  1037. typeset in math mode.  An alternative way of specifying the name of
  1038. the operation is to omit the optional argument (within \verb;[];), and
  1039. use \verb;\opname{;\^{name-of-operation}\verb;};, anywhere within the
  1040. body of the {\tt op} environment.
  1041.  
  1042. The \^{list-of-arguments} is a \mmexp\ that can span multiple lines;
  1043. force a newline with \cs\\.  If present it is placed within
  1044. parentheses.
  1045.  
  1046. The \^{result(s)} is also any \mmexp.  It is typeset to the right of
  1047. any arguments.
  1048.  
  1049. The \^{list-of-externals} takes the following form:
  1050. \begin{verse}
  1051. \verb;\ext{;    \\
  1052. \quad $\langle$optional \cs\Rd\ or \cs\Wr$\rangle$
  1053.     \^{external-name(s)} {\tt :\/} \^{external-types} \cs\\ \\
  1054. \quad $\langle$optional \cs\Rd\ or \cs\Wr$\rangle$
  1055.     \^{external-name(s)} {\tt :\/} \^{external-types} \cs\\ \\
  1056. \dots \\
  1057. \verb;};
  1058. \end{verse}
  1059. Alternatively, if the list of externals is long (say, more than five
  1060. lines) the {\tt externals\/} environmment can be used:
  1061. \begin{verse}
  1062. \verb;\begin{externals};    \\
  1063. \quad $\langle$optional \cs\Rd\ or \cs\Wr$\rangle$
  1064.     \^{external-name(s)} {\tt :\/} \^{external-types} \cs\\ \\
  1065. \quad $\langle$optional \cs\Rd\ or \cs\Wr$\rangle$
  1066.     \^{external-name(s)} {\tt :\/} \^{external-types} \cs\\ \\
  1067. \dots \\
  1068. \verb;\end{externals};
  1069. \end{verse}
  1070. \begin{dangerous}
  1071. Some people prefer the externals identifiers to appear lined up on the
  1072. left, some on the right.  If you want them to appear on the left, say
  1073. \cs\leftExternals; if you want them on the right, say
  1074. \cs\rightExternals.  The scope of the \cs\leftExternals\ and
  1075. \cs\rightExternals\ commands are the current group.  By default,
  1076. you get \cs\leftExternals.
  1077. \end{dangerous}
  1078.  
  1079.  
  1080. The \^{pre-condition} and \^{post-condition} take similar forms:
  1081. \begin{verse}
  1082. \verb;\pre{;\mmexp\verb;}; \\
  1083. \end{verse}
  1084. or
  1085. \begin{verse}
  1086. \verb;\begin{precond}; \\
  1087. \mmexp \\
  1088. \verb;\end{precond};
  1089. \end{verse}
  1090. and
  1091. \begin{verse}
  1092. \verb;\post{;\mmexp\verb;}; \\
  1093. \end{verse}
  1094. or
  1095. \begin{verse}
  1096. \verb;\begin{postcond}; \\
  1097. \mmexp \\
  1098. \verb;\end{postcond};
  1099. \end{verse}
  1100. Use the \cs\begin\dots\cs\end\ style if the \mmexp\ is longer
  1101. than a few lines.
  1102. All of the constructs mentioned in the section on formulas can be used
  1103. within pre- and post-conditions.
  1104.  
  1105. \section*{Proofs}
  1106.  
  1107. Here's an example of typesetting proofs in the ``natural deduction''
  1108. style. 
  1109.  
  1110. \begin{proof}
  1111.   \From E@1 \Or E@2     \\
  1112. 1   \From E@1    \\
  1113.     \Infer E@2 \Or E@1    \` $\vee$-I(h1) \\
  1114. 2   \From E@2        \\
  1115.     \Infer E@2 \Or E@1    \` $\vee$-I(h2) \\
  1116.   \Infer E@2 \Or E@1    \` $\vee$-E(h,1,2)\\
  1117. \end{proof}
  1118. \begin{verbatim}
  1119.         \begin{proof}
  1120.             \From E@1 \Or E@2                           \\
  1121.         1       \From E@1                               \\
  1122.                 \Infer E@2 \Or E@1  \by $\vee$-I(h1)    \\
  1123.         2       \From E@2                               \\
  1124.                 \Infer E@2 \Or E@1  \by $\vee$-I(h2)    \\
  1125.             \Infer E@2 \Or E@1      \by $\vee$-E(h,1,2) \\
  1126.         \end{proof}
  1127. \end{verbatim}
  1128.  
  1129. Proofs are embedded within the {\tt proof} environment.  (A proof does
  1130. not have to be within a {\tt vdm} environment.)  Each line of the
  1131. proof ends with \cs\\.  Lines that begin a subproof
  1132. have \cs\From\ after the equation number.  Lines that end a
  1133. subproof have \cs\Infer\ after the equation number.  Other lines
  1134. have \cs\& after the equation number (see next example).  If you
  1135. don't need an equation number, just omit it,  but you must have one of
  1136. either \cs\From, \cs\Infer\ or \cs\& on each proof line.
  1137. If you want to include a justification of a particular proof line at
  1138. the right hand end of the line, type it after a \cs\by.  \cs\by\
  1139. is optional; you needn't include it if you don't need a justification.
  1140.  
  1141. Points worth bearing in mind:
  1142. \begin{itemize}
  1143. \item    You are automatically placed in math mode after the
  1144.     \cs\From, \cs\Infer\ or \cs\&; the math mode ends
  1145.     at the next \cs\by\ or \cs\\.
  1146. \item    You {\em cannot} break a line in the middle simply by using
  1147.     \cs\\ before \cs\by; you must use separate proof lines
  1148.     to split a formula.
  1149. \item    You are within a {\tt tabbing} environment within a proof, so
  1150.     you can use all the usual {\tt tabbing} commands (\cs\=,
  1151.     \cs\>, etc.) to line things up across proof lines.  Note
  1152.     that you will explicitly have to enter math mode again after
  1153.     any of these commands though.
  1154. \end{itemize}
  1155.  
  1156. Here's another example:
  1157.  
  1158. \begin{proof}
  1159.   \From \forall{x\in X}{E(x); s\in X}    \\
  1160. 1 \&    \Not\exists{x\in X}{\Not E(x)}    \` $\Forall$-defn(h)\\
  1161. 2 \&    \Not\Not E(s/x)    \` $\Not\Exists$-E(1,h)\\
  1162.   \Infer E(s/x)                \\
  1163. \end{proof}
  1164. \begin{verbatim}
  1165. \begin{proof}
  1166.   \From \forall{x\in X}{E(x); s\in X}                       \\
  1167. 1 \&    \Not\exists{x\in X}{\Not E(x)} \by $\Forall$-defn(h)\\
  1168. 2 \&    \Not\Not E(s/x)             \by $\Not\Exists$-E(1,h)\\
  1169.   \Infer E(s/x)                                             \\
  1170. \end{proof}
  1171. \end{verbatim}
  1172.  
  1173. \begin{dangerous}
  1174. The amount of space used by the proof number can be changed by
  1175. changing the length \cs\ProofNumberWidth.  The distance from the
  1176. left margin to the proof number is dictated by \cs\ProofIndent.
  1177. \end{dangerous}
  1178.  
  1179.  
  1180. \section*{Customising the Style}
  1181.  
  1182. {\em Some people are never satisfied.}  We all know that it's true.
  1183. In order to cater for those who aren't satisfied with the output from
  1184. \Vdm, some attempt has been made to allow a limited degree of
  1185. customisation by the user.  In particular, you can alter some of the
  1186. internal spacing chosen by \Vdm, and even have your own macros called
  1187. at chosen places within \Vdm's macros.  Naturally, you are not advised
  1188. to try this unless you feel you have some idea of what you want, and
  1189. what you are doing.  In this section we list the things that you can
  1190. change, in order of increasing difficulty.
  1191.  
  1192. \subsection*{Changing the Spacing}
  1193.  
  1194. In several places, essentially arbitrary spacings have been chosen by
  1195. the author.  The dimensions of these spaces are given by {\em rubber
  1196. lengths.}\footnote{See the \LaTeX\ book for an explanation of rubber
  1197. lengths}  If you want to change any of them, use \LaTeX's
  1198. \cs\setlength\ or \cs\addtolength\ commands.
  1199. For example,
  1200. \begin{verbatim}
  1201.         \setlength{\postHeaderSkip}{13.33pt plus 2pt minus 1pt}
  1202. \end{verbatim}
  1203.  
  1204. \begin{dangerous}
  1205. The {\tt plus} and {\tt minus} parts of a length let you say how much
  1206. that length can grow or shrink by.  For example, {\tt 12pt plus 2pt
  1207. minus 1pt} means that the length will be in the range 11--14pt, with
  1208. 12pt as its ``natural'' length.
  1209. \end{dangerous}
  1210.  
  1211. The spaces in question all appear around \Vdm\ items such as
  1212. operations, and in between major parts of such items.  The names of
  1213. the lengths should convey where they apply.  The following table lists
  1214. all the lengths, and their default settings.  Note that an {\tt ex} is
  1215. about the height of an ``x'' in the current font, and an {\tt em} is
  1216. about the width of an ``M'' in the current font.
  1217.  
  1218. \begin{center}
  1219. \begin{tabular}{|l|l|l|}
  1220. \hline
  1221. \em Length        &\em Default size &\em Used within    \\
  1222. \hline
  1223. \cs\preOperationSkip    &2ex $+$ 0.5ex $\minus$ 0.2ex & {\tt op} env    \\
  1224. \cs\postOperationSkip    &2ex $+$ 0.5ex $\minus$ 0.2ex    &\\
  1225. \cs\postHeaderSkip        &.5ex $+$ .2ex $\minus$ .2ex    &\\
  1226. \cs\postExternalsSkip    &.5ex $+$ .2ex $\minus$ .2ex    &\\
  1227. \cs\postPreConditionSkip    &.5ex $+$ .2ex $\minus$ .2ex    &\\
  1228. \hline
  1229. \cs\preFunctionSkip    &2ex $+$ .5ex $\minus$ .2ex & {\tt fn} env    \\
  1230. \cs\postFunctionSkip    &2ex $+$ .5ex $\minus$ .2ex    &\\
  1231. \cs\betweenSignatureAndBodySkip&1.2ex $+$ .3ex $\minus$ .2ex    &\\
  1232. \cs\betweenFunctionAndPreSkip&1.2ex $+$ .3ex $\minus$ .2ex    &\\
  1233. \hline
  1234. \cs\preTypeSkip    &1.2ex $+$ .5ex $\minus$ .3ex & {\tt type} command    \\
  1235. \cs\postTypeSkip    &1.2ex $+$ .5ex $\minus$ .3ex    &\\
  1236. \hline
  1237. \cs\preCompositeSkip    &1.2ex $+$ .5ex $\minus$ .3ex & {\tt
  1238. composite} env    \\
  1239. \cs\postCompositeSkip    &1.2ex $+$ .5ex $\minus$ .3ex    &\\
  1240. \hline
  1241. \cs\preRecordSkip        &.75ex $+$ .3ex $\minus$ .2ex & {\tt
  1242. record} env    \\
  1243. \cs\postRecordSkip        &.75ex $+$ .3ex $\minus$ .2ex    &\\
  1244. \hline
  1245. \cs\preFormulaSkip        &1.2ex $+$ .5ex $\minus$ .3ex & {\tt
  1246. formula} env \\
  1247. \cs\postFormulaSkip        &1.2ex $+$ .5ex $\minus$ .3ex    &\\
  1248. \hline
  1249. \cs\preProofSkip        &.75ex $+$ .3ex $\minus$ .2ex & {\tt
  1250. proof} env    \\
  1251. \cs\postProofSkip        &.75ex $+$ .3ex $\minus$ .2ex    &\\
  1252. \hline
  1253. \end{tabular}
  1254. \end{center}
  1255.  
  1256. \subsection*{Controlling Line and Paragraph Breaks}
  1257.  
  1258. \TeX\ uses the notion of {\em penalties\/} to decide where line and
  1259. page breaks go.  Various values of penalty are used at places within
  1260. \Vdm\ to control breaks.  To fully understand how to choose breaks,
  1261. read {\em The \TeX{}book}.  However, put simply, penalties are whole
  1262. numbers in the range $\minus10000$~to $10000$.  A value of $10000$
  1263. means ``never break here,'' and a value of $\minus10000$ means
  1264. ``always break here.''  Values in between penalise or encourage
  1265. breaking proportionally, so that, e.g.,~a value of $\minus500$
  1266. encourages a break, but by no means forces it.
  1267.  
  1268. To assign to a penalty~\cs\p, write {\tt \cs\p=1000}, for example.
  1269. The table below list the penalties used by \Vdm, and their default
  1270. values.
  1271.  
  1272. \begin{center}
  1273. \begin{tabular}{|l|l|l|}
  1274. \hline
  1275. \em Penalty Name & Default Value & Where Used \\
  1276. \hline
  1277. \cs\preOperationPenalty    & 0    & {\tt op} env \\
  1278. \cs\preExternalPenalty    & 2000    & \\
  1279. \cs\prePreConditionPenalty    & 800    & \\
  1280. \cs\prePostConditionPenalty    & 500    & \\
  1281. \cs\postOperationPenalty    & -500    & \\
  1282. \hline
  1283. \cs\preFunctionPenalty    & 0    & {\tt fn} env \\
  1284. \cs\betweenSignatureAndBodyPenalty&500&\\
  1285. \cs\betweenFunctionAndPrePenalty&1000&\\
  1286. \cs\postFunctionPenalty    & -500    & \\
  1287. \hline
  1288. \cs\preRecordPenalty    & 0    & {\tt record} env\\
  1289. \cs\postRecordPenalty    & -100    & \\
  1290. \hline
  1291. \cs\preProofPenalty    & -100    & {\tt proof} env\\
  1292. \cs\postProofPenalty    & 0    & \\
  1293. \hline
  1294. \cs\preFormulaPenalty    & -100    & {\tt formula} env\\
  1295. \cs\postFormulaPenalty    & 0    & \\
  1296. \hline
  1297. \end{tabular}
  1298. \end{center}
  1299.  
  1300.  
  1301. \subsection*{Unforeseen Changes}
  1302.  
  1303. It is a truism that no matter how good the designer of a piece of
  1304. software is, he can never foresee all of its uses.  In this case, the
  1305. author is quite certain that people will use \Vdm\ for all sorts of
  1306. things apart from typesetting VDM specifications.  To cater for those
  1307. who find that \Vdm\ does almost, but not quite, what they want, a
  1308. number of {\em hooks\/} have been left in place.  These hooks are
  1309. macros, which at the moment do little or nothing, but which can be
  1310. redefined by users to change the basic operation of \Vdm.  Needless to
  1311. say, anyone wishing to redefine a hook should already be competent in
  1312. the ways of \LaTeX\ at least, and probably \TeX\ as well.  Rather than
  1313. trying to explain what the hooks do, and where they do it, the user
  1314. should look through the commented version of \Vdm\ (usually stored as
  1315. {\tt vdm.doc}) and figure it out for himself.  Below are listed all
  1316. the provided hooks, their default definitions, and where they are used.
  1317.  
  1318. \begin{center}\footnotesize
  1319. \begin{tabular}{|l|l|}
  1320. \hline
  1321. \em Name of hook & \em Default definition \\
  1322. \hline
  1323. \multicolumn{2}{|c|}{{\tt op} environment} \\
  1324. \hline
  1325. \cs\preOperationHook
  1326.     &\verb*;\penalty\preOperationPenalty ;\\
  1327. \cs\betweenHeaderAndExternalsHook
  1328.     &\verb*;\penalty\preExternalPenalty ;\\
  1329. \cs\betweenExternalsAndPreConditionHook
  1330.     &\verb*;\penalty\prePreConditionPenalty ;\\
  1331. \cs\betweenPreAndPostConditionHook
  1332.     &\verb*;\penalty\prePostConditionPenalty ;\\
  1333. \cs\postOperationHook
  1334.     &\verb*;\penalty\postOperationPenalty ;\\
  1335. \hline
  1336. \multicolumn{2}{|c|}{{\tt fn} environment} \\
  1337. \hline
  1338. \cs\preFunctionHook
  1339.         &\verb*;\penalty\preFunctionPenalty ;\\
  1340. \cs\betweenSignatureAndBodyHook
  1341.         &\verb*;\penalty\betweenSignatureAndBodyPenalty ; \\
  1342. \cs\betweenFunctionAndPreHook&\verb*;\vskip-\lastskip ;\\
  1343.         &\verb;\vskip\betweenFunctionAndPreSkip ;\\
  1344.         &\verb*;\penalty\betweenSignatureAndBodyPenalty ; \\
  1345. \cs\postFunctionHook
  1346.         &\verb*;\penalty\postFunctionPenalty ; \\
  1347. \hline
  1348. \multicolumn{2}{|c|}{{\tt record} environment} \\
  1349. \hline
  1350. \cs\preRecordHook
  1351.         &\verb*;\penalty\preRecordPenalty ;\\
  1352. \cs\postRecordHook
  1353.         &\verb*;\penalty\postRecordPenalty ; \\
  1354. \hline
  1355. \multicolumn{2}{|c|}{{\tt proof} environment} \\
  1356. \hline
  1357. \cs\preProofHook
  1358.         &\verb*;\penalty\preProofPenalty ;\\
  1359. \cs\postProofHook
  1360.         &\verb*;\penalty\postProofPenalty ; \\
  1361. \hline
  1362. \multicolumn{2}{|c|}{{\tt formula} environment} \\
  1363. \hline
  1364. \cs\preFormulaHook
  1365.         &\verb*;\penalty\preFormulaPenalty ;\\
  1366. \cs\postFormulaHook
  1367.         &\verb*;\penalty\postFormulaPenalty ; \\
  1368. \hline
  1369. \end{tabular}
  1370. \end{center}
  1371.  
  1372.  
  1373. \section*{Installing the \Vdm\ files}
  1374.  
  1375. Place the files {\tt vdm.sty} and {\tt vdm.doc} in your standard directory
  1376. for \LaTeX\ style files (your system administrator will know where this
  1377. is).  If you have the AMS fonts, change the appropriate line in {\tt
  1378. vdm.doc} (see instructions at the head of the file) and make the
  1379. corresponding change in {\tt vdm.sty}.  If you're on a UNIX\footnote{UNIX
  1380. is a trademark of AT\&T} system, you can make the {\tt .sty} file from
  1381. the {\tt .doc} file with the command:
  1382. \begin{verbatim}
  1383.    sed -e '/^[     ]*%/d' -e 's/%.*/%/' -e '/^$/d' vdm.doc > vdm.sty
  1384. \end{verbatim}
  1385. There are two characters between the square brackets: a tab and a
  1386. space.  If you're on some other system, figure out an equivalent
  1387. command, or make the two files the same.
  1388.  
  1389. If you want to keep up with changes to the \Vdm\ style, send a message
  1390. to the e-mail address on the front cover, and your name will be added
  1391. to a mailing list, so that you can be provided with updates.
  1392.  
  1393.  
  1394. \section*{Acknowledgements}
  1395.  
  1396. Many people have passed on useful suggestions and comments about \Vdm\
  1397. and this documentation; many thanks to all of them.  In particular I
  1398. would like to acknowledge the extensive testing done by Lynn Marshall
  1399. while preparing her thesis, and her helpful comments and ideas, and
  1400. the numerous worthwhile discussions with Cliff Jones.
  1401.  
  1402. \end{document}
  1403.  
  1404.